package com.szqhyxj.youxiangju.biz.partnerHome.equipment.subordinateList;

import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.partnerHome.equipment.bean.SubordinateInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * XiaoPanYu
 * on 2018/11/22
 */
public class SubordinateInfoAdapter extends BaseAdapter{

    private List<SubordinateInfo> infoList;

    private ImageView determine;
    private Drawable circle;
    private Drawable draw;

    public SubordinateInfoAdapter(List<SubordinateInfo> infoList,Drawable circle,Drawable draw){
        this.infoList = infoList;
        this.circle = circle;
        this.draw = draw;
    }



    @Override
    public int getCount(){
        return infoList.size();
    }

    @Override
    public Object getItem(int i){
        return infoList.get(i);
    }

    @Override
    public long getItemId(int i){
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup){
        if(view == null){
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_subordinate_info_item, null);
            ViewHolder holder = new ViewHolder(view);
            view.setTag(holder);
        }

        ViewHolder viewHolder = (ViewHolder) view.getTag();
        SubordinateInfo info = infoList.get(i);
        viewHolder.name.setText(info.getName());
        viewHolder.phone.setText("("+hidePhone(info.getPhone())+")");
        if(info.isConfirm()){
            viewHolder.determine.setImageDrawable(draw);
        }else {
            viewHolder.determine.setImageDrawable(circle);
        }

        return view;
    }

    static class ViewHolder{
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.phone)
        TextView phone;
        @BindView(R.id.determine)
        ImageView determine;

        ViewHolder(View view){
            ButterKnife.bind(this, view);
        }
    }

    private String hidePhone(String phone){
        String hideTxt = phone.substring(3,7);
        return phone.replace(hideTxt,"****");
    }


    @Override
    public void notifyDataSetChanged(){
        super.notifyDataSetChanged();

    }
}
